// Created from GenerationTemplate
// For Decisions HL7 Engine
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.Serialization;
using System.Reflection;
using DecisionsFramework.Design.Properties;
using Decisions.HL7.Generated.AbstractMessage;
using Decisions.HL7.DataTypes;
using ST = System.String;
using SI = System.String;
using TX = System.String;
using FT = System.String;
using IS = System.String;
using ID = System.String;
using SNM = System.String;

namespace Decisions.HL7.Message
{
    [DataContract]
	public class DSR_Q01 : AbstractMessage
    {
		/// Constructor
		public DSR_Q01() : base()
        {
			if (MSH != null) {
                MSH.MessageType = new MSG() { MessageCode = "DSR", TriggerEvent = "Q01" };
			}
        }

        /// -----------------------------
        /// -----------------------------
		[DataMember]
        [PropertyClassification("MSA",2)]
  	    [HL7Field(HL7Version.v23, 2, HL7Repeat.False, HL7Required.True,"MSA")]
  	    [HL7Field(HL7Version.v231, 2, HL7Repeat.False, HL7Required.True,"MSA")]
  	    [HL7Field(HL7Version.v24, 2, HL7Repeat.False, HL7Required.True,"MSA")]
  	    [HL7Field(HL7Version.v25, 3, HL7Repeat.False, HL7Required.True,"MSA")]
  	    [HL7Field(HL7Version.v251, 3, HL7Repeat.False, HL7Required.True,"MSA")]
  	    [HL7Field(HL7Version.v26, 4, HL7Repeat.False, HL7Required.True,"MSA")]
	    public MSA MSA {get;set;}

        /// -----------------------------
        /// -----------------------------
		[DataMember]
        [PropertyClassification("ERR",4)]
  	    [HL7Field(HL7Version.v23, 4, HL7Repeat.False, HL7Required.False,"ERR")]
  	    [HL7Field(HL7Version.v231, 4, HL7Repeat.False, HL7Required.False,"ERR")]
  	    [HL7Field(HL7Version.v24, 4, HL7Repeat.False, HL7Required.False,"ERR")]
  	    [HL7Field(HL7Version.v25, 4, HL7Repeat.False, HL7Required.False,"ERR")]
  	    [HL7Field(HL7Version.v251, 4, HL7Repeat.False, HL7Required.False,"ERR")]
  	    [HL7Field(HL7Version.v26, 5, HL7Repeat.False, HL7Required.False,"ERR")]
	    public ERR ERR {get;set;}

        /// -----------------------------
        /// -----------------------------
		[DataMember]
        [PropertyClassification("QAK",7)]
  	    [HL7Field(HL7Version.v23, 7, HL7Repeat.False, HL7Required.False,"QAK")]
  	    [HL7Field(HL7Version.v231, 7, HL7Repeat.False, HL7Required.False,"QAK")]
  	    [HL7Field(HL7Version.v24, 7, HL7Repeat.False, HL7Required.False,"QAK")]
  	    [HL7Field(HL7Version.v25, 5, HL7Repeat.False, HL7Required.False,"QAK")]
  	    [HL7Field(HL7Version.v251, 5, HL7Repeat.False, HL7Required.False,"QAK")]
  	    [HL7Field(HL7Version.v26, 6, HL7Repeat.False, HL7Required.False,"QAK")]
	    public QAK QAK {get;set;}

        /// -----------------------------
        /// -----------------------------
		[DataMember]
        [PropertyClassification("QRD",9)]
  	    [HL7Field(HL7Version.v23, 9, HL7Repeat.False, HL7Required.True,"QRD")]
  	    [HL7Field(HL7Version.v231, 9, HL7Repeat.False, HL7Required.True,"QRD")]
  	    [HL7Field(HL7Version.v24, 9, HL7Repeat.False, HL7Required.True,"QRD")]
  	    [HL7Field(HL7Version.v25, 6, HL7Repeat.False, HL7Required.True,"QRD")]
  	    [HL7Field(HL7Version.v251, 6, HL7Repeat.False, HL7Required.True,"QRD")]
  	    [HL7Field(HL7Version.v26, 7, HL7Repeat.False, HL7Required.True,"QRD")]
	    public QRD QRD {get;set;}

        /// -----------------------------
        /// -----------------------------
		[DataMember]
        [PropertyClassification("QRF",11)]
  	    [HL7Field(HL7Version.v23, 11, HL7Repeat.False, HL7Required.False,"QRF")]
  	    [HL7Field(HL7Version.v231, 11, HL7Repeat.False, HL7Required.False,"QRF")]
  	    [HL7Field(HL7Version.v24, 11, HL7Repeat.False, HL7Required.False,"QRF")]
  	    [HL7Field(HL7Version.v25, 7, HL7Repeat.False, HL7Required.False,"QRF")]
  	    [HL7Field(HL7Version.v251, 7, HL7Repeat.False, HL7Required.False,"QRF")]
  	    [HL7Field(HL7Version.v26, 8, HL7Repeat.False, HL7Required.False,"QRF")]
	    public QRF QRF {get;set;}

        /// -----------------------------
        /// -----------------------------
		[DataMember]
        [PropertyClassification("DSP",14)]
  	    [HL7Field(HL7Version.v23, 14, HL7Repeat.True, HL7Required.True,"DSP")]
  	    [HL7Field(HL7Version.v231, 14, HL7Repeat.True, HL7Required.True,"DSP")]
  	    [HL7Field(HL7Version.v24, 14, HL7Repeat.True, HL7Required.True,"DSP")]
  	    [HL7Field(HL7Version.v25, 8, HL7Repeat.True, HL7Required.True,"DSP")]
  	    [HL7Field(HL7Version.v251, 8, HL7Repeat.True, HL7Required.True,"DSP")]
  	    [HL7Field(HL7Version.v26, 9, HL7Repeat.True, HL7Required.True,"DSP")]
	    public DSP[] DSP {get;set;}

        /// -----------------------------
        /// -----------------------------
		[DataMember]
        [PropertyClassification("DSC",17)]
  	    [HL7Field(HL7Version.v23, 17, HL7Repeat.False, HL7Required.False,"DSC")]
  	    [HL7Field(HL7Version.v231, 17, HL7Repeat.False, HL7Required.False,"DSC")]
  	    [HL7Field(HL7Version.v24, 17, HL7Repeat.False, HL7Required.False,"DSC")]
  	    [HL7Field(HL7Version.v25, 9, HL7Repeat.False, HL7Required.False,"DSC")]
  	    [HL7Field(HL7Version.v251, 9, HL7Repeat.False, HL7Required.False,"DSC")]
  	    [HL7Field(HL7Version.v26, 10, HL7Repeat.False, HL7Required.False,"DSC")]
	    public DSC DSC {get;set;}

        /// -----------------------------
        /// -----------------------------
		[DataMember]
        [PropertyClassification("SFT",2)]
  	    [HL7Field(HL7Version.v25, 2, HL7Repeat.True, HL7Required.False,"SFT")]
  	    [HL7Field(HL7Version.v251, 2, HL7Repeat.True, HL7Required.False,"SFT")]
  	    [HL7Field(HL7Version.v26, 2, HL7Repeat.True, HL7Required.False,"SFT")]
	    public SFT[] SFT {get;set;}

        /// -----------------------------
        /// -----------------------------
		[DataMember]
        [PropertyClassification("UAC",3)]
  	    [HL7Field(HL7Version.v26, 3, HL7Repeat.False, HL7Required.False,"UAC")]
	    public UAC UAC {get;set;}



		#region Parser Helpers and Conrete Impls

        internal override Stack<string> ConsumeTextSegments(Stack<string> availableData, HL7ParserOptions options) {

				if (HL7Version.v23 == options.Version) {
		 MSA = PopSegmentParseAndCheckRequired<MSA>(availableData, options, "MSA");
		 ERR = PopSegmentParseAndCheckRequired<ERR>(availableData, options, "ERR");
		 QAK = PopSegmentParseAndCheckRequired<QAK>(availableData, options, "QAK");
		 QRD = PopSegmentParseAndCheckRequired<QRD>(availableData, options, "QRD");
		 QRF = PopSegmentParseAndCheckRequired<QRF>(availableData, options, "QRF");
		 DSP = PopSegmentParseAndCheckRequiredArray<DSP>(availableData, options, "DSP");
		 DSC = PopSegmentParseAndCheckRequired<DSC>(availableData, options, "DSC");
		}
		if (HL7Version.v231 == options.Version) {
		 MSA = PopSegmentParseAndCheckRequired<MSA>(availableData, options, "MSA");
		 ERR = PopSegmentParseAndCheckRequired<ERR>(availableData, options, "ERR");
		 QAK = PopSegmentParseAndCheckRequired<QAK>(availableData, options, "QAK");
		 QRD = PopSegmentParseAndCheckRequired<QRD>(availableData, options, "QRD");
		 QRF = PopSegmentParseAndCheckRequired<QRF>(availableData, options, "QRF");
		 DSP = PopSegmentParseAndCheckRequiredArray<DSP>(availableData, options, "DSP");
		 DSC = PopSegmentParseAndCheckRequired<DSC>(availableData, options, "DSC");
		}
		if (HL7Version.v24 == options.Version) {
		 MSA = PopSegmentParseAndCheckRequired<MSA>(availableData, options, "MSA");
		 ERR = PopSegmentParseAndCheckRequired<ERR>(availableData, options, "ERR");
		 QAK = PopSegmentParseAndCheckRequired<QAK>(availableData, options, "QAK");
		 QRD = PopSegmentParseAndCheckRequired<QRD>(availableData, options, "QRD");
		 QRF = PopSegmentParseAndCheckRequired<QRF>(availableData, options, "QRF");
		 DSP = PopSegmentParseAndCheckRequiredArray<DSP>(availableData, options, "DSP");
		 DSC = PopSegmentParseAndCheckRequired<DSC>(availableData, options, "DSC");
		}
		if (HL7Version.v25 == options.Version) {
		 MSA = PopSegmentParseAndCheckRequired<MSA>(availableData, options, "MSA");
		 ERR = PopSegmentParseAndCheckRequired<ERR>(availableData, options, "ERR");
		 QAK = PopSegmentParseAndCheckRequired<QAK>(availableData, options, "QAK");
		 QRD = PopSegmentParseAndCheckRequired<QRD>(availableData, options, "QRD");
		 QRF = PopSegmentParseAndCheckRequired<QRF>(availableData, options, "QRF");
		 DSP = PopSegmentParseAndCheckRequiredArray<DSP>(availableData, options, "DSP");
		 DSC = PopSegmentParseAndCheckRequired<DSC>(availableData, options, "DSC");
		 SFT = PopSegmentParseAndCheckRequiredArray<SFT>(availableData, options, "SFT");
		}
		if (HL7Version.v251 == options.Version) {
		 MSA = PopSegmentParseAndCheckRequired<MSA>(availableData, options, "MSA");
		 ERR = PopSegmentParseAndCheckRequired<ERR>(availableData, options, "ERR");
		 QAK = PopSegmentParseAndCheckRequired<QAK>(availableData, options, "QAK");
		 QRD = PopSegmentParseAndCheckRequired<QRD>(availableData, options, "QRD");
		 QRF = PopSegmentParseAndCheckRequired<QRF>(availableData, options, "QRF");
		 DSP = PopSegmentParseAndCheckRequiredArray<DSP>(availableData, options, "DSP");
		 DSC = PopSegmentParseAndCheckRequired<DSC>(availableData, options, "DSC");
		 SFT = PopSegmentParseAndCheckRequiredArray<SFT>(availableData, options, "SFT");
		}
		if (HL7Version.v26 == options.Version) {
		 MSA = PopSegmentParseAndCheckRequired<MSA>(availableData, options, "MSA");
		 ERR = PopSegmentParseAndCheckRequired<ERR>(availableData, options, "ERR");
		 QAK = PopSegmentParseAndCheckRequired<QAK>(availableData, options, "QAK");
		 QRD = PopSegmentParseAndCheckRequired<QRD>(availableData, options, "QRD");
		 QRF = PopSegmentParseAndCheckRequired<QRF>(availableData, options, "QRF");
		 DSP = PopSegmentParseAndCheckRequiredArray<DSP>(availableData, options, "DSP");
		 DSC = PopSegmentParseAndCheckRequired<DSC>(availableData, options, "DSC");
		 SFT = PopSegmentParseAndCheckRequiredArray<SFT>(availableData, options, "SFT");
		 UAC = PopSegmentParseAndCheckRequired<UAC>(availableData, options, "UAC");
		}
			if (availableData != null && availableData.Count > 0) {
				ConsumeZSegmentsFromText(availableData, options);
			}
            return availableData;
        
        }

        private static Dictionary<string, bool> SEGMENT_VERSION_REQUIRED_MAP = new Dictionary<string, bool>();

		protected override Dictionary<string, bool> MAP_OF_SEGMENT_TO_REQUIRED
        {
            get
			{
				return SEGMENT_VERSION_REQUIRED_MAP;
			}
        }

		public override string HL7ENTITY_TYPE_NAME
        {
            get {
				return "DSR_Q01";
			}
        }

        static DSR_Q01() {

             SetupStaticPropertyMap(SEGMENT_VERSION_REQUIRED_MAP, typeof(DSR_Q01));

        }

		#endregion

		public override string GetER7(HL7ParserOptions options)
		{
			List<string> segmentData = new List<string>();
			if (MSH != null) {
				segmentData.Add(MSH.GetER7(options));
			}
			if (MSA != null) {
				segmentData.Add(MSA.GetER7(options));
			}
			if (ERR != null) {
				segmentData.Add(ERR.GetER7(options));
			}
			if (QAK != null) {
				segmentData.Add(QAK.GetER7(options));
			}
			if (QRD != null) {
				segmentData.Add(QRD.GetER7(options));
			}
			if (QRF != null) {
				segmentData.Add(QRF.GetER7(options));
			}
			if (DSP != null && DSP.Length > 0) {
				for (int i = 0; i < DSP.Length; i++) {
					segmentData.Add(DSP[i].GetER7(options));
				}
			}
			if (DSC != null) {
				segmentData.Add(DSC.GetER7(options));
			}
			if (SFT != null && SFT.Length > 0) {
				for (int i = 0; i < SFT.Length; i++) {
					segmentData.Add(SFT[i].GetER7(options));
				}
			}
			if (UAC != null) {
				segmentData.Add(UAC.GetER7(options));
			}
           segmentData.AddRange(GetZSegmentsER7(options));
		   return string.Join(HL7ParserConstants.SEGMENT_SEPARATOR, segmentData.ToArray());
        
        }


    }
}

